﻿package  
{
    import com.pixelbreaker.ui.osx.*;
    import com.shawnblais.sitecontrol.*;
    import flash.display.*;
    import flash.events.*;
    import flash.geom.*;
    import flash.text.*;
    import flash.utils.*;

    public class Main extends MovieClip
    {
        protected var site:SiteControl;
        public var framerateMonitor_mc:MovieClip;
        protected var sleepDelay:Number = 2000;
        protected var frameRate:uint = 30;
        protected var sleepTimer:Timer;
        protected var sleepOverlay:Sprite;

    [Frame(factoryClass="Preloader")]
    [SWF(backgroundColor="#FFFFFF", width="900", height="600")]
        public function Main()
        { 
            addFrameScript(0, this.frame1);
            this.addEventListener(Event.ADDED_TO_STAGE,init);
            return;
        }// end function

        protected function onStageResize(event:Event = null)
        {
            this.site.view.onStageResize();
            return;
        }// end function

        function frame1()
        {
            stop();
            return;
        }// end function

        protected function enterSleepMode(event:Event)
        {
            stage.frameRate = 5;
            this.sleepOverlay = new MovieClip();
            var _loc_2:* = new Matrix();
            _loc_2.createGradientBox(stage.stageWidth, stage.stageHeight, Math.PI / 180 * 90);
            this.sleepOverlay.graphics.beginGradientFill(GradientType.LINEAR, [16777215, 16777215], [0.9, 0], [50, 200], _loc_2);
            this.sleepOverlay.graphics.drawRect(0, 0, stage.stageWidth, stage.stageHeight);
            this.sleepOverlay.graphics.endFill();
            var _loc_3:* = new TextField();
            _loc_3.autoSize = TextFieldAutoSize.LEFT;
            _loc_3.antiAliasType = AntiAliasType.ADVANCED;
            _loc_3.text = "Sleeping...";
            _loc_3.x = stage.stageWidth / 2 - _loc_3.width / 2;
            _loc_3.y = 25;
            var _loc_4:* = new TextFormat("Arial");
            _loc_4.bold = true;
            _loc_4.size = 11;
            _loc_3.setTextFormat(_loc_4);
            this.sleepOverlay.addChild(_loc_3);
            this.sleepOverlay.mouseChildren = false;
            this.sleepOverlay.mouseEnabled = false;
            addChildAt(this.sleepOverlay, stage.numChildren);
            return;
        }// end function

        protected function onMouseLeave(event:Event):void
        {
            this.sleepTimer = new Timer(this.sleepDelay, 1);
            this.sleepTimer.start();
            this.sleepTimer.addEventListener(TimerEvent.TIMER_COMPLETE, this.enterSleepMode);
            stage.addEventListener(MouseEvent.MOUSE_MOVE, this.onMouseReturn);
            return;
        }// end function
 
        protected function onMouseReturn(event:Event):void
        {
            this.sleepTimer.stop();
            stage.frameRate = this.frameRate;
            if (this.sleepOverlay)
            {
                removeChild(this.sleepOverlay);
            }
            this.sleepOverlay = undefined;
            return;
        }// end function
 
        protected function init(event:Event) : void
        {
            this.removeEventListener(Event.ADDED_TO_STAGE, this.init);
            stage.align = StageAlign.TOP_LEFT;
            stage.scaleMode = StageScaleMode.NO_SCALE;
            stage.frameRate = 30;
            MacMouseWheel.setup(stage);
            this.site = new SiteControl(stage);
            stage.addEventListener(Event.RESIZE, this.onStageResize);
            this.onStageResize();
            return;
        }// end function

    }
}
